package thread.demo.hashMap;

import java.util.HashMap;
import java.util.Map;

public class HashMapTest001 {
  public static void main(String[] args) {
    HashMap<String, String> map = new HashMap<>();
    
    map.put("1", "1");
    map.put("2", "2");
    
    for (Map.Entry<String, String> item : map.entrySet())
      System.out.printf("k=%s,v=%s%n", item.getKey(), item.getValue());
    
    // 存在key putIfAbsent 失败
    System.out.println(map.putIfAbsent("1", "3"));
    
    for (Map.Entry<String, String> item : map.entrySet())
      System.out.printf("k=%s,v=%s%n", item.getKey(), item.getValue());
  }
}
